
.EQU	PTCON_VAL,	0X0000	; DISABLE PWM & 1:1 POSTSCALER
.EQU	PTPER_VAL,	9592	; 9592 for 100k MASTER TIME BASE PERIOD VALUE
.EQU	MDC_VAL,	500		; DUTY (50%?)
.EQU	PHASE1_VAL,	6396	; PRIMARY PHASE SHIFT
.EQU	DTR1_VAL,	300		; DEAD TIME
.EQU	ALTDTR1_VAL,300		; ALTERNATE DEAD TIME
.EQU	IOCON1_VAL,	0XC000	; PWM1H AS PWM OUTPUT
.EQU	PWMCON1_VAL,0X0100	; MDC PROVIDE DUTY CYCLE
.EQU	FCLCON1_VAL,0X0003	; FAUILT INPUT DISABLED (FAULT CURRENT-LIMIT CONTROL) 

.EQU	TRGCON1_VAL,0X0001
.EQU	TRIG1_VAL,	0

.EQU	SDC2_VAL,	9592
.EQU	PDC2_VAL,	5000
.EQU	PHASE2_VAL,	4818	; 4818 FOR 200k
.EQU	DTR2_VAL, 	300
.EQU	ALTDTR2_VAL,300
.EQU	IOCON2_VAL,	0XCC00	; PWM2H AS PWM OUTPUT
.EQU	PWMCON2_VAL,0X0200	; PTPER PROVIDE DUTY CYCLE
.EQU	SPHASE2_VAL, 6396
.EQU	FCLCON2_VAL,0X0003	; FAULT INPUT DISABLED

.INCLUDE	"p33FJ16GS502.INC"
.INCLUDE	"MACRO.INC"

.GLOBAL		PWM_INITIAL

.TEXT

PWM_INITIAL:
	MOVFF	#PTCON_VAL,	PTCON
	MOVFF	#PTPER_VAL,	PTPER
	MOVFF	#MDC_VAL,	MDC
	
	MOVFF	#PHASE1_VAL,PTCON
	MOVFF	#DTR1_VAL,	DTR1
	MOVFF	#ALTDTR1_VAL,ALTDTR1
	MOVFF	#IOCON1_VAL,IOCON1
	MOVFF	#PWMCON1_VAL,PWMCON1
	MOVFF	#FCLCON1_VAL,FCLCON1
	MOVFF	#TRGCON1_VAL,TRGCON1
	MOVFF	#TRIG1_VAL,	TRIG1
	
	MOVFF	#SDC2_VAL, SDC2
	MOVFF	#PDC2_VAL, PDC2
	MOVFF	#PHASE2_VAL,PHASE2
	MOVFF	#DTR2_VAL,DTR2
	MOVFF	#ALTDTR2_VAL,ALTDTR2
	MOVFF	#IOCON2_VAL,IOCON2
	MOVFF	#PWMCON2_VAL,PWMCON2
	MOVFF	#FCLCON2_VAL,FCLCON2
	
	;BSET	PTCON,	#PTEN		; ENABLE PWM MODULE AFTER EVERYTHING WERE SETTLED

	RETURN
	.END